package alp.starcode.edms.manage.controller;

import alp.starcode.common.mybatis.page.Pagination;
import alp.starcode.edms.manage.model.dto.ExpertLibraryDto;
import alp.starcode.edms.manage.model.vo.ExpertLibraryVo;
import alp.starcode.edms.manage.service.LibraryManageService;
import alp.starcode.edms.framework.base.BaseController;
import alp.starcode.common.web.result.Result;
import io.swagger.annotations.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 专家库管理 控制层
 *
 * @author liwang
 * 2023-08-14 09:18
 **/
@Api(tags = "专家库管理-专家库相关接口")
@RestController
@RequestMapping("manage")
@Validated
public class LibraryManageController extends BaseController {

  /**
   * 专家库管理 业务处理类
   */
  @Resource
  private LibraryManageService libraryManageService;

  /**
   * 分页查询专家库列表
   *
   * @param expertLibraryName 专家库名称
   * @param pagination        分页对象
   * @return 专家库列表
   */
  @GetMapping("pageExpertLibrary.do")
  @ApiOperation("分页获取专家库列表")
  @ApiOperationSupport(order = 10)
  @ApiImplicitParams({
          @ApiImplicitParam(name = "expertLibraryName", value = "专家库名称", required = false, example = "计算机科学专家库"),
          @ApiImplicitParam(name = "pagination.current", value = "当前页码", required = false, example = "1"),
          @ApiImplicitParam(name = "pagination.size", value = "每页大小", required = false, example = "10")
  })
  public Result<Pagination<ExpertLibraryVo>> pageExpertLibrary(
          @RequestParam(required = false) String expertLibraryName,
          Pagination<ExpertLibraryVo> pagination) {
    return Result.success(libraryManageService.pageExpertLibrary(expertLibraryName, pagination));
  }

  /**
   * 根据ID查询专家库详情
   *
   * @param expertLibraryId 专家库ID
   * @return 专家库详情
   */
  @GetMapping("getExpertLibraryById.do")
  @ApiOperation("根据ID查询专家库详情")
  @ApiOperationSupport(order = 15)
  @ApiImplicitParams({
          @ApiImplicitParam(name = "expertLibraryId", value = "专家库ID", required = true, example = "1234567890")
  })
  public Result<ExpertLibraryVo> getExpertLibraryById(String expertLibraryId) {
    return Result.success(libraryManageService.getExpertLibraryById(expertLibraryId));
  }

  /**
   * 新增专家库
   *
   * @param expertLibraryDto 专家库信息
   * @return 操作结果
   */
  @PostMapping("addExpertLibrary.do")
  @ApiOperation("新增专家库")
  @ApiOperationSupport(order = 20)
  @ApiImplicitParams({
          @ApiImplicitParam(name = "expertLibraryId", value = "专家库ID,新增操作不需要传参", required = false, example = "1234567890"),
          @ApiImplicitParam(name = "expertLibraryName", value = "专家库名称", required = true, example = "计算机科学专家库"),
          @ApiImplicitParam(name = "adminLimit", value = "管理员数量上限", required = true, example = "10"),
          @ApiImplicitParam(name = "description", value = "专家库描述", required = false, example = "计算机科学领域的专家库")
  })
  public Result<Boolean> addExpertLibrary(@Valid ExpertLibraryDto expertLibraryDto) {
    libraryManageService.addExpertLibrary(expertLibraryDto);
    return Result.success();
  }

  /**
   * 修改专家库
   *
   * @param expertLibraryDto 专家库信息
   * @return 操作结果
   */
  @PostMapping("updateExpertLibrary.do")
  @ApiOperation("修改专家库")
  @ApiOperationSupport(order = 25)
  @ApiImplicitParams({
          @ApiImplicitParam(name = "expertLibraryId", value = "专家库ID", required = true, example = "1234567890"),
          @ApiImplicitParam(name = "expertLibraryName", value = "专家库名称", required = true, example = "计算机科学专家库"),
          @ApiImplicitParam(name = "adminLimit", value = "管理员数量上限", required = true, example = "10"),
          @ApiImplicitParam(name = "description", value = "专家库描述", required = false, example = "计算机科学领域的专家库")
  })
  public Result<Boolean> updateExpertLibrary(@Valid ExpertLibraryDto expertLibraryDto) {
    libraryManageService.updateExpertLibrary(expertLibraryDto);
    return Result.success();
  }

  /**
   * 删除专家库
   *
   * @param expertLibraryId 专家库ID
   * @return 操作结果
   */
  @PostMapping("removeExpertLibrary.do")
  @ApiOperation("删除专家库")
  @ApiOperationSupport(order = 30)
  @ApiImplicitParams({
          @ApiImplicitParam(name = "expertLibraryId", value = "专家库ID", required = true, example = "1234567890")
  })
  public Result<Boolean> removeExpertLibrary(String expertLibraryId) {
    libraryManageService.removeExpertLibrary(expertLibraryId);
    return Result.success();
  }

  /**
   * 获取所有专家库列表（不分页）
   *
   * @return 专家库列表
   */
  @GetMapping("getAllExpertLibraryList.do")
  @ApiOperation("获取所有专家库列表")
  @ApiOperationSupport(order = 35)
  public Result<List<ExpertLibraryVo>> getAllExpertLibraryList() {
    return Result.success(libraryManageService.getAllExpertLibraryList());
  }
} 